package com.longge;

import java.util.Arrays;

public class CheckDynasty {

    public boolean checkDynasty(int[] places) {
        int count = 0;
        for (int place : places) {
            if (place == 0) count++;
        }
        int[] nums = Arrays.stream(places).filter(num -> num != 0).sorted().toArray();
        for (int i = 1; i < nums.length; i++) {
            if (nums[i]==nums[i-1]){
                return false;
            }
            count -= nums[i] - nums[i - 1] - 1;
            if (count < 0) return false;
        }
        return true;
    }

    public static void main(String[] args) {
        new CheckDynasty().checkDynasty(new int[]{0, 6, 9, 0, 7});
    }
}
